home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / cgterm10.zip / PIBASYN3.MOD < prev    next >
Text File  |  1993-04-01  |  27KB  |  521 lines

  1. (*----------------------------------------------------------------------*)
  2. (*      Async_Carrier_Detect --- Check for modem carrier detect         *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. FUNCTION Async_Carrier_Detect : BOOLEAN;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Function:   Async_Carrier_Detect                                 *)
  10. (*                                                                      *)
  11. (*     Purpose:    Looks for modem carrier detect                       *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Flag := Async_Carrier_Detect : BOOLEAN;                       *)
  16. (*                                                                      *)
  17. (*           Flag is set TRUE if carrier detected, else FALSE.          *)
  18. (*                                                                      *)
  19. (*     Calls:  None                                                     *)
  20. (*                                                                      *)
  21. (*----------------------------------------------------------------------*)
  22.  
  23. BEGIN (* Async_Carrier_Detect *)
  24.  
  25.    Async_Carrier_Detect := ODD( Port[ UART_MSR + Async_Base ] SHR 7 ) OR
  26.                            Async_Hard_Wired_On;
  27.  
  28. END   (* Async_Carrier_Detect *);
  29.  
  30. (*----------------------------------------------------------------------*)
  31. (*      Async_Carrier_Drop --- Check for modem carrier drop/timeout     *)
  32. (*----------------------------------------------------------------------*)
  33.  
  34. FUNCTION Async_Carrier_Drop : BOOLEAN;
  35.  
  36. (*----------------------------------------------------------------------*)
  37. (*                                                                      *)
  38. (*     Function:   Async_Carrier_Drop                                   *)
  39. (*                                                                      *)
  40. (*     Purpose:    Looks for modem carrier drop/timeout                 *)
  41. (*                                                                      *)
  42. (*     Calling Sequence:                                                *)
  43. (*                                                                      *)
  44. (*        Flag := Async_Carrier_Drop : BOOLEAN;                         *)
  45. (*                                                                      *)
  46. (*           Flag is set TRUE if carrier dropped, else FALSE.           *)
  47. (*                                                                      *)
  48. (*     Calls:  None                                                     *)
  49. (*                                                                      *)
  50. (*----------------------------------------------------------------------*)
  51.  
  52. BEGIN (* Async_Carrier_Drop *)
  53.  
  54.    Async_Carrier_Drop := NOT ( ODD( Port[ UART_MSR + Async_Base ] SHR 7 ) OR
  55.                                Async_Hard_Wired_On );
  56.  
  57. END   (* Async_Carrier_Drop *);
  58.  
  59. (*----------------------------------------------------------------------*)
  60. (*      Async_Term_Ready --- Set terminal ready status                  *)
  61. (*----------------------------------------------------------------------*)
  62.  
  63. PROCEDURE Async_Term_Ready( Ready_Status : BOOLEAN );
  64.  
  65. (*----------------------------------------------------------------------*)
  66. (*                                                                      *)
  67. (*     Procedure:  Async_Term_Ready                                     *)
  68. (*                                                                      *)
  69. (*     Purpose:    Sets terminal ready status                           *)
  70. (*                                                                      *)
  71. (*     Calling Sequence:                                                *)
  72. (*                                                                      *)
  73. (*        Async_Term_Ready( Ready_Status : BOOLEAN );                   *)
  74. (*                                                                      *)
  75. (*           Ready_Status --- Set TRUE to set terminal ready on,        *)
  76. (*                            Set FALSE to set terminal ready off.      *)
  77. (*                                                                      *)
  78. (*     Calls:  None                                                     *)
  79. (*                                                                      *)
  80. (*----------------------------------------------------------------------*)
  81.  
  82. VAR
  83.    Mcr_Value: BYTE;
  84.  
  85. BEGIN (* Async_Term_Ready *)
  86.  
  87.    Mcr_Value := Port[ UART_MCR + Async_Base ];
  88.  
  89.    IF ODD( Mcr_Value ) THEN Mcr_Value := Mcr_Value - 1;
  90.  
  91.    IF Ready_Status THEN Mcr_Value := Mcr_Value + 1;
  92.  
  93.    Port[ UART_MCR + Async_Base ] := Mcr_Value;
  94.  
  95.    Async_Clear_Errors;
  96.  
  97. END   (* Async_Term_Ready *);
  98.  
  99. (*----------------------------------------------------------------------*)
  100. (*          Async_Buffer_Check --- Check if character in buffer         *)
  101. (*----------------------------------------------------------------------*)
  102.  
  103. FUNCTION Async_Buffer_Check : BOOLEAN;
  104.  
  105. (*----------------------------------------------------------------------*)
  106. (*                                                                      *)
  107. (*     Function:   Async_Buffer_Check                                   *)
  108. (*                                                                      *)
  109. (*     Purpose:    Check if character in buffer                         *)
  110. (*                                                                      *)
  111. (*     Calling Sequence:                                                *)
  112. (*                                                                      *)
  113. (*        Flag := Async_Buffer_Check : BOOLEAN;                         *)
  114. (*                                                                      *)
  115. (*           Flag returned TRUE if character received in buffer,        *)
  116. (*           Flag returned FALSE if no character received.              *)
  117. (*                                                                      *)
  118. (*     Calls:  None                                                     *)
  119. (*                                                                      *)
  120. (*     Remarks:                                                         *)
  121. (*                                                                      *)
  122. (*       This routine only checks if a character has been received      *)
  123. (*       and thus can be read; it does NOT return the character.        *)
  124. (*       Use Async_Receive to read the character.                       *)
  125. (*                                                                      *)
  126. (*----------------------------------------------------------------------*)
  127.  
  128. BEGIN   (* Async_Buffer_Check *)
  129.  
  130.    Async_Buffer_Check := ( Async_Buffer_Head <> Async_Buffer_Tail );
  131.  
  132. END     (* Async_Buffer_Check *);
  133.  
  134. (*----------------------------------------------------------------------*)
  135. (*          Async_Line_Error --- Check if line status error occurred    *)
  136. (*----------------------------------------------------------------------*)
  137.  
  138. FUNCTION Async_Line_Error( VAR Error_Flags: BYTE ) : BOOLEAN;
  139.  
  140. (*----------------------------------------------------------------------*)
  141. (*                                                                      *)
  142. (*     Function:   Async_Line_Error                                     *)
  143. (*                                                                      *)
  144. (*     Purpose:    Check if line status error occurred                  *)
  145. (*                                                                      *)
  146. (*     Calling Sequence:                                                *)
  147. (*                                                                      *)
  148. (*        Flag := Async_Line_Error(VAR Error_Flags: BYTE): BOOLEAN;   *)
  149. (*                                                                      *)
  150. (*           Error_Flags --- Current error flags                        *)
  151. (*                                                                      *)
  152. (*           Flag returned TRUE if line status error occurred,          *)
  153. (*           Flag returned FALSE if no error.                           *)
  154. (*                                                                      *)
  155. (*     Calls:  None                                                     *)
  156. (*                                                                      *)
  157. (*     Remarks:                                                         *)
  158. (*                                                                      *)
  159. (*        The line status error flag is cleared here.                   *)
  160. (*                                                                      *)
  161. (*----------------------------------------------------------------------*)
  162.  
  163. BEGIN   (* Async_Line_Error *)
  164.  
  165.    Async_Line_Error       := ( Async_Line_Error_Flags <> 0 );
  166.    Error_Flags            := Async_Line_Error_Flags;
  167.    Async_Line_Error_Flags := 0;
  168.  
  169. END     (* Async_Line_Error  *);
  170.  
  171. (*----------------------------------------------------------------------*)
  172. (*            Async_Ring_Detect --- Check for phone ringing             *)
  173. (*----------------------------------------------------------------------*)
  174.  
  175. FUNCTION Async_Ring_Detect : BOOLEAN;
  176.  
  177. (*----------------------------------------------------------------------*)
  178. (*                                                                      *)
  179. (*     Function:   Async_Ring_Detect                                    *)
  180. (*                                                                      *)
  181. (*     Purpose:    Looks for phone ringing                              *)
  182. (*                                                                      *)
  183. (*     Calling Sequence:                                                *)
  184. (*                                                                      *)
  185. (*        Flag := Async_Ring_Detect : BOOLEAN;                          *)
  186. (*                                                                      *)
  187. (*           Flag is set TRUE if ringing detected, else FALSE.          *)
  188. (*                                                                      *)
  189. (*     Calls:  None                                                     *)
  190. (*                                                                      *)
  191. (*----------------------------------------------------------------------*)
  192.  
  193. BEGIN (* Async_Ring_Detect *)
  194.  
  195.    Async_Ring_Detect := ODD( Port[ UART_MSR + Async_Base ] SHR 6 );
  196.  
  197. END   (* Async_Ring_Detect *);
  198.  
  199. (*----------------------------------------------------------------------*)
  200. (*          Async_Send_Break --- Send break (attention) signal          *)
  201. (*----------------------------------------------------------------------*)
  202.  
  203. PROCEDURE Async_Send_Break;
  204.  
  205. (*----------------------------------------------------------------------*)
  206. (*                                                                      *)
  207. (*     Procedure:  Async_Send_Break                                     *)
  208. (*                                                                      *)
  209. (*     Purpose:    Sends break signal over communications port          *)
  210. (*                                                                      *)
  211. (*     Calling Sequence:                                                *)
  212. (*                                                                      *)
  213. (*        Async_Send_Break;                                             *)
  214. (*                                                                      *)
  215. (*     Calls:  None                                                     *)
  216. (*                                                                      *)
  217. (*----------------------------------------------------------------------*)
  218.  
  219. VAR
  220.    Old_Lcr   : BYTE;
  221.    Break_Lcr : BYTE;
  222.  
  223. BEGIN (* Async_Send_Break *)
  224.  
  225.    Old_Lcr   := Port[ UART_LCR + Async_Base ];
  226.    Break_Lcr := Old_Lcr;
  227.  
  228.    IF Break_Lcr >  127 THEN Break_Lcr := Break_Lcr - 128;
  229.    IF Break_Lcr <=  63 THEN Break_Lcr := Break_Lcr +  64;
  230.  
  231.    Port[ UART_LCR + Async_Base ] := Break_Lcr;
  232.  
  233.    DELAY( Async_Break_Length * 10 );
  234.  
  235.    Port[ UART_LCR + Async_Base ] := Old_Lcr;
  236.  
  237. END   (* Async_Send_Break *);
  238.  
  239. (*----------------------------------------------------------------------*)
  240. (*     Async_Send_String --- Send string over communications port       *)
  241. (*----------------------------------------------------------------------*)
  242.  
  243. PROCEDURE Async_Send_String( S : AnyStr );
  244.  
  245. (*----------------------------------------------------------------------*)
  246. (*                                                                      *)
  247. (*     Procedure:  Async_Send_String                                    *)
  248. (*                                                                      *)
  249. (*     Purpose:    Sends string out over communications port            *)
  250. (*                                                                      *)
  251. (*     Calling Sequence:                                                *)
  252. (*                                                                      *)
  253. (*        Async_Send_String( S : AnyStr );                              *)
  254. (*                                                                      *)
  255. (*           S --- String to send                                       *)
  256. (*                                                                      *)
  257. (*     Calls:  Async_Send                                               *)
  258. (*                                                                      *)
  259. (*----------------------------------------------------------------------*)
  260.  
  261. VAR
  262.    I : INTEGER;
  263.  
  264. BEGIN  (* Async_Send_String *)
  265.  
  266.   FOR I := 1 TO LENGTH( S ) DO
  267.      Async_Send( S[I] )
  268.  
  269. END    (* Async_Send_String *);
  270.  
  271. (*----------------------------------------------------------------------*)
  272. (*     Async_Send_String_With_Delays --- Send string with timed delays  *)
  273. (*----------------------------------------------------------------------*)
  274.  
  275. PROCEDURE Async_Send_String_With_Delays( S          : AnyStr;
  276.                                          Char_Delay : INTEGER;
  277.                                          EOS_Delay  : INTEGER  );
  278.  
  279. (*----------------------------------------------------------------------*)
  280. (*                                                                      *)
  281. (*     Procedure:  Async_Send_String_With_Delays                        *)
  282. (*                                                                      *)
  283. (*     Purpose:    Sends string out over communications port with       *)
  284. (*                 specified delays for each character and at the       *)
  285. (*                 end of the string.                                   *)
  286. (*                                                                      *)
  287. (*     Calling Sequence:                                                *)
  288. (*                                                                      *)
  289. (*        Async_Send_String_With_Delays( S          : AnyStr ;          *)
  290. (*                                       Char_Delay : INTEGER;          *)
  291. (*                                       EOS_Delay  : INTEGER );        *)
  292. (*                                                                      *)
  293. (*           S          --- String to send                              *)
  294. (*           Char_Delay --- Number of milliseconds to delay after       *)
  295. (*                          sending each character                      *)
  296. (*           EOS_Delay  --- Number of milleseconds to delay after       *)
  297. (*                          sending last character in string            *)
  298. (*                                                                      *)
  299. (*     Calls:  Async_Send                                               *)
  300. (*             Async_Send_String                                        *)
  301. (*             Length                                                   *)
  302. (*             Delay                                                    *)
  303. (*                                                                      *)
  304. (*     Remarks:                                                         *)
  305. (*                                                                      *)
  306. (*        This routine is useful when writing routines to perform       *)
  307. (*        non-protocol uploads.  Many computer systems require delays   *)
  308. (*        between receipt of characters for correct processing.  The    *)
  309. (*        delay for end-of-string usually applies when the string       *)
  310. (*        represents an entire line of a file.                          *)
  311. (*                                                                      *)
  312. (*        If delays are not required, Async_Send_String is faster.      *)
  313. (*        This routine will call Async_Send_String is no character      *)
  314. (*        delay is to be done.                                          *)
  315. (*                                                                      *)
  316. (*----------------------------------------------------------------------*)
  317.  
  318. VAR
  319.    I : INTEGER;
  320.  
  321. BEGIN  (* Async_Send_String_With_Delays *)
  322.  
  323.    IF Char_Delay <= 0 THEN
  324.       Async_Send_String( S )
  325.    ELSE
  326.       FOR I := 1 TO LENGTH( S ) DO
  327.          BEGIN
  328.             Async_Send( S[I] );
  329.             Delay( Char_Delay );
  330.          END;
  331.  
  332.    IF EOS_Delay > 0 THEN Delay( EOS_Delay );
  333.  
  334. END    (* Async_Send_String_With_Delays *);
  335.  
  336. (*----------------------------------------------------------------------*)
  337. (*      Async_Percentage_Used --- Report Percentage Buffer Filled       *)
  338. (*----------------------------------------------------------------------*)
  339.  
  340. FUNCTION Async_Percentage_Used : REAL;
  341.  
  342. (*----------------------------------------------------------------------*)
  343. (*                                                                      *)
  344. (*     Function:   Async_Percent_Used                                   *)
  345. (*                                                                      *)
  346. (*     Purpose:    Reports percentage of com buffer currently filled    *)
  347. (*                                                                      *)
  348. (*     Calling Sequence:                                                *)
  349. (*                                                                      *)
  350. (*        Percentage := Async_Percentage_Used : Real;                   *)
  351. (*                                                                      *)
  352. (*           Percentage gets how much of buffer is filled;              *)
  353. (*           value goes from 0.0 (empty) to 1.0 (totally full).         *)
  354. (*                                                                      *)
  355. (*     Calls:  None                                                     *)
  356. (*                                                                      *)
  357. (*     Remarks:                                                         *)
  358. (*                                                                      *)
  359. (*       This routine is helpful when incorporating handshaking into    *)
  360. (*       a communications program.  For example, assume that the host   *)
  361. (*       computer uses the XON/XOFF (DC1/DC3) protocol.  Then the       *)
  362. (*       PC program should issue an XOFF  to the host when the value    *)
  363. (*       returned by Async_Percentage_Used > .75 or so.  When the       *)
  364. (*       utilization percentage drops below .25 or so, the PC program   *)
  365. (*       should transmit an XON.                                        *)
  366. (*                                                                      *)
  367. (*----------------------------------------------------------------------*)
  368.  
  369. BEGIN (* Async_Percentage_Used *)
  370.  
  371.    Async_Percentage_Used := Async_Buffer_Used / ( Async_Buffer_Size + 1 );
  372.  
  373. END   (* Async_Percentage_Used *);
  374.  
  375. (*----------------------------------------------------------------------*)
  376. (*     Async_Purge_Buffer --- Purge communications input buffer         *)
  377. (*----------------------------------------------------------------------*)
  378.  
  379. PROCEDURE Async_Purge_Buffer;
  380.  
  381. (*----------------------------------------------------------------------*)
  382. (*                                                                      *)
  383. (*     Procedure:  Async_Purge_Buffer                                   *)
  384. (*                                                                      *)
  385. (*     Purpose:    Purges communications input buffer                   *)
  386. (*                                                                      *)
  387. (*     Calling Sequence:                                                *)
  388. (*                                                                      *)
  389. (*        Async_Purge_Buffer;                                           *)
  390. (*                                                                      *)
  391. (*     Calls:  Async_Receive                                            *)
  392. (*                                                                      *)
  393. (*----------------------------------------------------------------------*)
  394.  
  395. VAR
  396.    C: CHAR;
  397.    L: INTEGER;
  398.  
  399. BEGIN  (* Async_Purge_Buffer *)
  400.  
  401.    L     := 10000 DIV Async_Baud_Rate;
  402.  
  403.    IF L <= 0 THEN
  404.       L := 3;
  405.  
  406.    REPEAT
  407.       DELAY( L )
  408.    UNTIL ( NOT Async_Receive( C ) );
  409.  
  410. END    (* Async_Purge_Buffer *);
  411.  
  412. (*----------------------------------------------------------------------*)
  413. (*          Async_Peek --- Peek ahead in communications buffer          *)
  414. (*----------------------------------------------------------------------*)
  415.  
  416. FUNCTION Async_Peek( Nchars : INTEGER ) : CHAR;
  417.  
  418. (*----------------------------------------------------------------------*)
  419. (*                                                                      *)
  420. (*     Function:   Async_Peek                                           *)
  421. (*                                                                      *)
  422. (*     Purpose:    Peeks ahead in comm buffer                           *)
  423. (*                                                                      *)
  424. (*     Calling Sequence:                                                *)
  425. (*                                                                      *)
  426. (*        Ch := Async_Peek( NChars: INTEGER) : CHAR;                    *)
  427. (*                                                                      *)
  428. (*           NChars --- # of characters to peek ahead                   *)
  429. (*           Ch     --- returned (peeked) character                     *)
  430. (*                                                                      *)
  431. (*     Calls:  None                                                     *)
  432. (*                                                                      *)
  433. (*----------------------------------------------------------------------*)
  434.  
  435. VAR
  436.    I: INTEGER;
  437.  
  438. BEGIN (* Async_Peek *)
  439.  
  440.    I := ( Async_Buffer_Tail + NChars ) MOD Async_Buffer_Size;
  441.  
  442.    IF ( I > Async_Buffer_Head ) THEN
  443.       Async_Peek := CHR( 0 )
  444.    ELSE
  445.       Async_Peek := Async_Buffer_Ptr^[ I ];
  446.  
  447. END   (* Async_Peek *);
  448.  
  449. (*----------------------------------------------------------------------*)
  450. (*         Async_Setup_Port --- Setup port address and IRQ line         *)
  451. (*----------------------------------------------------------------------*)
  452.  
  453. PROCEDURE Async_Setup_Port( ComPort       : INTEGER;
  454.                             Base_Address  : INTEGER;
  455.                             IRQ_Line      : INTEGER;
  456.                             RS_232_Base   : INTEGER );
  457.  
  458. (*----------------------------------------------------------------------*)
  459. (*                                                                      *)
  460. (*     Procedure:  Async_Setup_Port                                     *)
  461. (*                                                                      *)
  462. (*     Purpose:    Sets up port address and IRQ line                    *)
  463. (*                                                                      *)
  464. (*     Calling Sequence:                                                *)
  465. (*                                                                      *)
  466. (*        Async_Setup_Port( ComPort       : INTEGER;                    *)
  467. (*                          Base_Address  : INTEGER;                    *)
  468. (*                          IRQ_Line      : INTEGER;                    *)
  469. (*                          RS_232_Base   : INTEGER );                  *)
  470. (*                                                                      *)
  471. (*           ComPort      --- which port (1 though MaxComPorts)         *)
  472. (*           Base_Address --- Base address of port                      *)
  473. (*           IRQ_Line     --- IRQ line for interrupts for port          *)
  474. (*           RS_232_Base  --- RS 232 base address for port              *)
  475. (*                                                                      *)
  476. (*     Calls:  None                                                     *)
  477. (*                                                                      *)
  478. (*----------------------------------------------------------------------*)
  479.  
  480. BEGIN  (* Async_Setup_Port *)
  481.  
  482.    IF ( ( ComPort > 0 ) AND ( ComPort <= MaxComPorts ) ) THEN
  483.       BEGIN
  484.          Com_Base [ComPort] := Base_Address;
  485.          Com_Irq  [ComPort] := IRQ_Line;
  486.          Com_RS232[ComPort] := RS_232_Base;
  487.       END;
  488.  
  489. END    (* Async_Setup_Port *);
  490.  
  491. (*----------------------------------------------------------------------*)
  492. (*         Async_Release_Buffers --- Release buffers for serial ports   *)
  493. (*----------------------------------------------------------------------*)
  494.  
  495. PROCEDURE Async_Release_Buffers;
  496.  
  497. (*----------------------------------------------------------------------*)
  498. (*                                                                      *)
  499. (*     Procedure:  Async_Release_Buffers;                               *)
  500. (*                                                                      *)
  501. (*     Purpose:    Releases send and receive buffers                    *)
  502. (*                                                                      *)
  503. (*     Calling Sequence:                                                *)
  504. (*                                                                      *)
  505. (*        Async_Release_Buffers;                                        *)
  506. (*                                                                      *)
  507. (*     Calls:  None                                                     *)
  508. (*                                                                      *)
  509. (*----------------------------------------------------------------------*)
  510.  
  511. BEGIN  (* Async_Release_Buffers *)
  512.  
  513.                              (* If port open, close it down first.  *)
  514.    IF Async_Open_Flag THEN
  515.       Async_Close( FALSE );
  516.  
  517.    FREEMEM( Async_Buffer_Ptr  , Async_Buffer_Size  + 1 );
  518.    FREEMEM( Async_OBuffer_Ptr , Async_OBuffer_Size + 1 );
  519.  
  520. END    (* Async_Release_Buffers *);
  521.